//
//  Record.m
//  MMTest
//
//  Created by liujianlong on 2022/9/21.
//

#import "SingleData.h"

@implementation SingleData
-(NSMutableString *)L_data{
    if (!_L_data) {
        _L_data = [[NSMutableString alloc] init];
    }
    return _L_data;
}
-(NSMutableString *)R_data{
    if (!_R_data) {
        _R_data = [[NSMutableString alloc] init];
    }
    return _R_data;
}
-(CGFloat)L_avg{
    if (self.L_data.length <= 0) { return 0; }
    NSString *temp = [self.L_data substringToIndex:self.L_data.length - 1];
    NSArray *array = [temp componentsSeparatedByString:@","];
    if (array == nil || array.count <= 0 || (array.count == 1 && [array[0] isEqualToString:@""])) { return 0; }
    CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
    return avg;
}
-(CGFloat)R_avg{
    if (self.R_data.length <= 0) { return 0; }
    NSString *temp = [self.R_data substringToIndex:self.R_data.length - 1];
    NSArray *array = [temp componentsSeparatedByString:@","];
    if (array == nil || array.count <= 0 || (array.count == 1 && [array[0] isEqualToString:@""])) { return 0; }
    CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
    return avg;
}
- (CGFloat)altitude{
    return  (1013.25 - _airPressure / 100) * 9.0;
}
+ (NSArray *)bg_unionPrimaryKeys
{
    return @[@"startStamp"];
}
- (id)copyWithZone:(NSZone *)zone{
    SingleData *model = [SingleData allocWithZone:zone];
    model.userName = self.userName;
    model.startStamp = self.startStamp;
    model.stamp = self.stamp;
    model.deviceName = self.deviceName;
    model.mac = self.mac;
    
    model.L_current = self.L_current;
    model.L_max = self.L_max;
    model.L_avg = self.L_avg;
    model.L_step = self.L_step;
    model.L_batterlevel = self.L_batterlevel;
    model.L_total_avg = self.L_total_avg;

    model.R_current = self.R_current;
    model.R_max = self.R_max;
    model.R_avg = self.R_avg;
    model.R_step = self.R_step;
    model.R_batterlevel = self.R_batterlevel;
    model.R_total_avg = self.R_total_avg;

    model.temperature = self.temperature;
    model.airPressure = self.airPressure;
    model.altitude = self.altitude;
    
    model.L_data = self.L_data;
    model.L_max_data = self.L_max_data;
    model.R_data = self.R_data;
    model.R_max_data = self.R_max_data;
    
    model.num = self.num;
    
    model.type = self.type;
    return model;
}


- (nonnull id)mutableCopyWithZone:(nullable NSZone *)zone {
    return [self copyWithZone:zone];
}

@end
